local skel=fk.CreateSkill{
    name="ym_water__suirang",
    tgas={Skill.Compulsory},
}


Fk:loadTranslationTable{
    ["ym_water__suirang"]="绥壤",
    [":ym_water__suirang"]="锁定技，邻家回合开始前，你可以移动其攻击范围外角色区域内一张牌，若不为场上的牌，你执行一个拥有“攻南”的出牌阶段。",
    ["#ym_water__suirang-move"]="绥壤：移动其攻击范围外角色区域内一张牌",
    ["#ym_water__suirang-tomove"]="绥壤：选择一名角色，将牌移动给其",

}

skel:addEffect(fk.PreTurnStart,{
    anim_type = "control",
    can_trigger= function(self, event, target, player, data)
        if player:hasSkill(skel.name) then
         return target==player:getNextAlive() or target==player:getLastAlive()
        end
      end,
      on_cost = function (self, event, target, player, data)
        local room = player.room
        local tars=table.filter(room.alive_players,function(p)
            return not target:inMyAttackRange(p)
        end)
        if #tars>0 then
            local tar=room:askToChoosePlayers(player,
            {
                targets=tars,
                min_num=1,
                max_num=1,
                skill_name=skel.name,
                prompt="绥壤：移动其攻击范围外角色区域内一张牌",
                cancelable=true,
            })
            if #tar>0 then
                event:setCostData(self, {tos = tar[1]})
                return true
            end
        end
      end,
      on_use = function (self, event, target, player, data)
        local room = player.room
        local tar=event:getCostData(self).tos
        local card_data = {}
        local to = room:askToChoosePlayers(player, {
            min_num = 1,
            max_num = 1,
            targets = room:getOtherPlayers(tar),
            skill_name = skel.name,
            prompt = "#ym_water__suirang-tomove",
            cancelable = false,
          })[1]
        local dat = {
          from = player.id,
          to = to.id,
          skillName = skel.name,
          prompt = "#ym_water__suirang-move::"..to.id,
        }
        local visible_data = {}
        if not tar:isKongcheng() then
          table.insert(card_data, {"$Hand", tar:getCardIds("h")})
          for _, id in ipairs(tar:getCardIds("h")) do
            if not player:cardVisible(id) then
              visible_data[tostring(id)] = false
            end
          end
        end
        local cards = table.filter(tar:getCardIds("e"), function (id)
          return tar:canMoveCardInBoardTo(to, id)
        end)
        local field={}
        if #cards > 0 then
          table.insert(card_data, {"$Equip", cards})
          table.insertTable(field,cards)
        end
        if #tar:getCardIds("j") > 0 then
          table.insert(card_data, {"$Judge", tar:getCardIds("j")})
          table.insertTable(field,tar:getCardIds("j"))
          for _, id in ipairs(tar:getCardIds("j")) do
            if not tar:cardVisible(id) then
              visible_data[tostring(id)] = false
            end
          end
        end
        if next(visible_data) == nil then visible_data = nil end
        dat.visible_data = visible_data
        local card = room:askToPoxi(player, {
          poxi_type = skel.name,
          data = card_data,
          extra_data = dat,
          cancelable = false,
        })
        room:moveCardTo(card, room:getCardArea(card[1]), to, fk.ReasonJustMove, skel.name, nil, false, player)
        if not table.contains(field,card[1]) then
          room:handleAddLoseSkills(player,"ym_water__gongnan")
            player:gainAnExtraPhase(Player.Play,skel.name,false,{
                suirang_cause=true,
            })
            
        end
        
      end,

})


skel:addEffect(fk.EventPhaseEnd,{
    anim_type = "control",
    mute=true,
    can_refresh = function(self, event, target, player, data)
        return player:hasSkill(skel.name) and target==player and data.extra_data and data.extra_data.suirang_cause
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        room:handleAddLoseSkills(player,"-ym_water__gongnan")

    end,
})


Fk:addPoxiMethod{
    name = "ym_water__suirang",
    prompt = function (data, extra_data)
      return extra_data.prompt
    end,
    card_filter = function (to_select, selected, data, extra_data)
      return #selected == 0
    end,
    feasible = function(selected, data)
      return #selected == 1
    end,
    default_choice = function(data)
      return {data[1][2][1]}
    end,
  }









return skel